$(function () {
    selectAboutUs();
})

function selectAboutUs() {
    let data = myAjax("/back/aboutUs/findAboutUs", "", "get");
    data = data.list;
    let html = '';
    html += '<tr>\n' +
        '            <td>' + data.id + '</td>\n' +
        '            <td>' + data.title + '</td>\n' +
        '            <td><img src="' + data.bgimg + '" width="150px"/></td>\n' +
        '            <td><div class="content">' + data.content + '</div></td>\n' +
        '            <td><a href="javascript:edit(' + data.id + ')">编辑</a>&nbsp;' +
        '            </td>\n' +
        '        </tr>';
    $("#findAboutUs").html(html);
}

function edit(id) {
    let data = myAjax("/back/aboutUs/updatAboutUs", {id: id}, "get");
    data = data.aboutUsModel;
    let html = '';
    html += '<div>主题名称：<input id="title" type="text" value=' + data.title + '></div>\n' +
        '    <div>主题背景：<input id="bgimg" type="file" onclick="hide()" value=' + data.bgimg + '/></div>\n' +
        '    <div><img id="img" src="' + data.bgimg + '" width="120px" style="margin-left: 52px"/></div>\n' +
        '    <div>“关于我们”信息：<textarea id="content">' + data.content + '</textarea></div>\n' +
        '    <div><button onclick="updateAboutUs()">确定修改</button></div>';
    $("#editAboutUs").html(html);
}

function hide() {
    $("#img").attr("src", "");
}

//更新HeadandFoot的信息
function updateAboutUs() {
    let data1 = new FormData();
    data1.append("title", $("#title").val());
    data1.append("bgimg", $("#bgimg")[0].files[0]);
    data1.append("content", $("#content").val());
    let data = myFileAjax("/back/aboutUs/updatAboutUs", data1, "post");
    if (data.result == 1) {
        alert("更新成功");
    } else {
        alert("更新失败");
    }
}